/*
 jQuery.Turbolinks ~ https://github.com/kossnocorp/jquery.turbolinks
 jQuery plugin for drop-in fix binded events problem caused by Turbolinks

 The MIT License
 Copyright (c) 2012-2013 Sasha Koss & Rico Sta. Cruz
 */

var $, $document;

$ = window.jQuery || (typeof require === "function" ? require('jquery') : void 0);

$document = $(document);

$.turbo = {
    version: '2.0.1',
    isReady: false,
    use: function(load, fetch) {
        return $document.off('.turbo').on("" + load + ".turbo", this.onLoad).on("" + fetch + ".turbo", this.onFetch);
    },
    addCallback: function(callback) {
        if ($.turbo.isReady) {
            return callback($);
        } else {
            return $document.on('turbo:ready', function() {
                return callback($);
            });
        }
    },
    onLoad: function() {
        $.turbo.isReady = true;
        return $document.trigger('turbo:ready');
    },
    onFetch: function() {
        return $.turbo.isReady = false;
    },
    register: function() {
        $(this.onLoad);
        return $.fn.ready = this.addCallback;
    }
};

$.turbo.register();

$.turbo.use('page:load', 'page:fetch');